<?php
class ProductsController extends AppController {
    
    var $name = 'Products';
    var $helpers = array ('Html', 'Form', 'Time', 'Cache');
    var $components = array('RequestHandler');
    
    
    function add() {
        $this->set('title_for_layout', 'Add new product');
        if (!empty($this->data)) {
            $this->Product->create();
            if ($this->Product->save($this->data)) {
                $this->Product->Auction->create();
                $this->Product->Auction->saveField('product_id', $this->Product->id);
                $this->Session->setFlash("New product has been added!");
                $this->redirect(array('controller' => 'users','action' => 'index'));
            } else {
                //$this->Session->setFlash('Please check the errors');
            }
            //$this->redirect(array('action' => 'index'));
        }
    }
    
    function edit($id = null) {
        $this->set('title_for_layout', 'Edit product description');
        $this->Product->id = $id;
        if (empty($this->data)) {
            $this->data = $this->Product->read();
        } else {
            if ($this->Product->save($this->data)) {
                //$this->Session->setFlash('Your comment has been updated');
                $this->redirect(array('controller' => 'users','action' => 'index'));
            }
        }
    }
    
    function view($id = null) {
        $product = $this->Product->findById($id);
#        debug($product);
        $this->set('product', $product);
        $this->set('title_for_layout', $product['Product']['name']);
    }
    
    
}
?>
